import { VueComponent } from 'vue-typescript'
import { AboutComponent } from '../../views/about/about';
import {dataService} from '../../service/dataService';
import * as VueRouter from 'vue-router';
// import './login_bg.jpg';
import '../../img/login_bg.jpg';
import '../../img/group.png';

import '../../img/group2.png';

import '../../img/group4.png';
import '../../img/login.png';



import '../../favicon.ico';

// import ''
// require('../../img/login_bg.jpg')
var VueTables = require('vue-tables');
Vue.use(VueTables.client,{
    filterable:false,
    compileTemplates:true
});
Vue.use(VueRouter);
// Vue.use(VueResource);

var router = new VueRouter();



@VueComponent({
    template: require('./login.html'),
    style: require('./login.scss')
})
export class LoginComponent extends Vue {
    el:'#login';
    components:({
        AboutComponent:AboutComponent,
        vclienttable:any,
    })
    authError=""
    user={
        name:"",
        password:""
    }
    ready=function(){
         this.authError="";
         //设置背景图片
        $('body').css({
            'backgroundImage': 'url(./img/login_bg.jpg)',
            // 'backgroundImage': 'url(./login_bg.jpg)',
            
            'backgroundAttachment': 'fixed',
            'backgroundSize': 'cover'
        });
      
    }
    

    login=function(){
        // console.log("loging")
        if($('#loginBtn').hasClass('disabled')){
            return;
        }
        var loginData;
        dataService().User.login(this.user.name,this.user.password).then((res)=>{
            
            if(!(res&&res.jwtToken)){
                // this.authError="请输入正确的用户名和密码"
                bootbox.alert('请输入正确的用户名和密码');
                return;
            }

            loginData=res;
            // console.log("logining")
            // console.log(res)
           
            window.sessionStorage.setItem("logined","yes");

            var userInfo=JSON.stringify(loginData);
            
            window.sessionStorage.setItem("userInfo",userInfo);
            window.sessionStorage.setItem("userName",res.userName);
            

            router.go('/home');

        },function(err){
            console.log(err)
        })
      
        
    };
    getInquiryList=function(){
        // dataService().Inquiry.getInquiryList();
    }
    package:string = 'vue-typescript';
    repo:string = 'https://github.com/itsFrank/vue-typescript';
    // result1:string= null;
    // formatDatetime = function(datetime) {
    // if (datetime === null) {
    //     return "[null]";
    // } else {
    //     return datetime.format("YYYY-MM-DD HH:mm:ss");
    // }
    // }

}
